package com.denlaku.longan.controller.impl;

import com.denlaku.longan.controller.MyCollectController;
import com.denlaku.longan.core.Current;
import com.denlaku.longan.http.Resp;
import com.denlaku.longan.http.Return;
import com.denlaku.longan.qo.MyCollectQuery;
import com.denlaku.longan.service.MyCollectService;
import com.denlaku.longan.vo.MyCollect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tianx
 */
@RestController
public class MyCollectControllerImpl implements MyCollectController {
    @Autowired
    private MyCollectService myCollectService;

    @Override
    public Return<Long> add(@RequestBody MyCollect myCollect) {
        myCollectService.add(myCollect);
        return Resp.success(myCollect.getId());
    }

    @Override
    public Return<Void> delete(@RequestBody MyCollectQuery query) {
        Long userId = Current.getUserId();
        query.setUserId(userId);
        myCollectService.delete(query);
        return Resp.success();
    }

    @Override
    public Return<Void> clear() {
        Long userId = Current.getUserId();
        myCollectService.deleteByUid(userId);
        return Resp.success();
    }

    @Override
    public Return<List<MyCollect>> list(@RequestBody MyCollectQuery query) {
        Long userId = Current.getUserId();
        query.setUserId(userId);
        List<MyCollect> list = myCollectService.list(query);
        return Resp.success(list);
    }
}
